/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SIMRS.Radiologi.widget;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.JToolBar;

/**
 *
 * @author sano
 */
public class Toolbar extends JToolBar{
    private static final long serialVersionUID = 1L;
    private BufferedImage gradientImage;
    private BufferedImage lightImage;
    private Color light = new Color(1F, 1F, 1F, 0.5F);
    private Color dark = new Color(1F, 1F, 1F, 0.0F);
    private Color black = Color.BLACK;
    private Color warna = Color.GREEN;

    public Toolbar() {
        super();
        setFloatable(false);
        setBorder(BorderFactory.createEmptyBorder(3, 3, 4, 3));
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        setUpGradientImage();
        setUpLightImage();
        if(isOpaque()){
            g.drawImage(gradientImage, 0, 0, getWidth(), getHeight(), null);
            g.drawImage(lightImage, 0, 0, getWidth(), getHeight()/2, null);
        }
    }

    private void setUpGradientImage() {
        gradientImage = new BufferedImage(1, getHeight(), BufferedImage.TYPE_INT_ARGB);
        GradientPaint paint = new GradientPaint(0, 0, warna, 0, getHeight(), black);

        Graphics2D g2 = (Graphics2D) gradientImage.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(paint);
        g2.fillRect(0, 0, 1, getHeight());
        g2.dispose();
    }

    private void setUpLightImage() {
        lightImage = new BufferedImage(1, getHeight()/2, BufferedImage.TYPE_INT_ARGB);
        GradientPaint paint = new GradientPaint(0, 0, dark, 0, getHeight(), black);

        Graphics2D g2 = (Graphics2D) gradientImage.getGraphics();
        g2.setPaint(paint);
        g2.fillRect(0, 0, 1, getHeight()/2);
        g2.dispose();
    }
    
}
